package com.ruitu.mall_98_2.mine;

import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;

import com.beanu.arad.base.my_base.MyBaseActivity;
import com.beanu.arad.widget.NoScrollViewPager;
import com.beanu.arad.widget.progressactivity.ProgressLayout;
import com.ruitu.mall_98_2.R;
import com.ruitu.mall_98_2.mine.fragment.FragmentCoupon;
import com.ruitu.mall_98_2.mine.fragment.FragmentInvalidCoupon;

public class UserCouponActivity extends MyBaseActivity {

    private NoScrollViewPager viewPager;

    @Override
    protected int getLayoutRes() {
        return R.layout.activity_user_coupon;
    }

    @Override
    protected ProgressLayout findProgressLayout() {
        return null;
    }


    TabLayout tabLayout;

    @Override
    protected void initViews() {
        super.initViews();
        setHeadTitle("我的优惠券");
        viewPager = findViewById(R.id.viewPager);
        tabLayout = findViewById(R.id.tabLayout);

        adapter = new CouconFragmentViewPagerAdapter(getSupportFragmentManager());
        viewPager.setAdapter(adapter);
        tabLayout.setupWithViewPager(viewPager);
    }

    String titleName[] = {"未使用", "使用记录", "已失效"};
    CouconFragmentViewPagerAdapter adapter;

    class CouconFragmentViewPagerAdapter extends FragmentPagerAdapter {

        public CouconFragmentViewPagerAdapter(FragmentManager fm) {
            super(fm);
        }

        @Override
        public Fragment getItem(int position) {
            if (position == 0) {
                return FragmentCoupon.newInstance(position);
            }
            return FragmentInvalidCoupon.newInstance(position);
        }

        @Override
        public int getCount() {
            return 3;
        }

        @Override
        public CharSequence getPageTitle(int position) {
            return titleName[position];
        }
    }
}
